div{
width: 200px;
height: 200px;
background: blue;
}
.animate{
animation-name: move;
animation-duration: 5s;
animation-iteration-count: 1;
}
@keyframes move {
0%{
background-color:blue;
}
33%{
transform:translate(1000px);
}
66%{
background-color:red;
}
100%{
background-color:red;
}
}
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style2.css"/>
<script>
function startAnimation()
{
var x = document.getElementById("a1");
x.classList.add("animate");
}
</script>
</head>
<body>
<div id="a1"></div>
<br/>
<button onclick="startAnimation()">Start Animation</button>
</body>
</html>

Post a Comment